<template>
  <div>
    <template v-if="params.tableMain == 0">
      <el-row style="justify-content: space-between">
        <el-row>
          <p class="pinformation">方案列表</p>
          <p class="totalStyle">共 {{ 0 }} 条数据</p>
        </el-row>
      </el-row>
      <el-table ref="projectRef" :data="projectList" v-loading="projectLoading">
        <el-table-column
          show-overflow-tooltip
          label="方案编号"
          align="center"
          prop="projectCode"
        />
        <el-table-column label="检测时间" align="center">
          <template #default="scope">
            <span v-if="scope.row.startDate == scope.row.endDate">{{scope.row.startDate}}</span>
            <span v-else>{{ scope.row.startDate }} 至 {{ scope.row.endDate }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-row>
        <p class="pinformation">附件列表</p>
        <p class="totalStyle">共 {{ annexList.length }} 条数据</p>
      </el-row>
      <el-table
        ref="projectRef"
        :data="annexList"
        v-loading="annexLoading"
        height="25vh"
      >
        <el-table-column label="序号" type="index" width="70" align="center" />
        <el-table-column label="文件名称" align="center" show-overflow-tooltip>
          <template #default="scope">
            <span @click="downloadFile(scope.row)" class="fileNameHover">{{
              scope.row.fileName
            }}</span>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <p class="pinformation">操作</p>
    <el-row>
      <el-button
        style="background-color: #6200ff; color: #fff"
        @click="handleUseRecord"
        >仪器使用记录</el-button
      >
    </el-row>
    <instrumentDia :lMId="props.params.taskId" ref="instrumentRef"/>
  </div>
</template>

<script setup>
import instrumentDia from "@/components/instrument/index";
import { getProjectList, labTask, listAnnex } from "@/api/lab/labMethod";
const { proxy } = getCurrentInstance();

const projectList = ref([]);
const projectLoading = ref(false);

const params = ref({ isChild: 0 });

const annexList = ref([]);
const annexLoading = ref(false);

const instrumentRef = ref(null)

const props = defineProps({
  params: {
    type: Object,
    required: true,
  },
  pId: {
    type: String,
  },
});

function listProject() {
  getProjectList({ lMId: props.params.taskId }).then((res) => {
    projectList.value = res.data;
  });
}

nextTick(() => {
  params.value = props.params;
  if (params.value.tableMain == 0) {
    listProject();
    if(!props.pId) return;
    listAnnex({ groupId: props.params.taskId, typeId: 27 }).then((res) => {
      annexLoading.value = false;
      annexList.value = res.data;
    });
  }
});

function downloadFile(row) {
  proxy.$modal.loading("正在下载文件，请稍候...");
  proxy.$download.localFile(row.fileId, row.fileName).then((res) => {
    proxy.$modal.closeLoading();
  });
}

function handleUseRecord() {
  instrumentRef.value.handleUseRecord(true)
}

</script>
